namespace MTOM_Library.MtomWebService
{
    using MTOM_Library.Properties;
    using System;
    using System.CodeDom.Compiler;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Runtime.CompilerServices;
    using System.Threading;
    using System.Web.Services;
    using System.Web.Services.Description;
    using System.Web.Services.Protocols;
    using System.Xml.Serialization;

    [WebServiceBinding(Name="MTOMSoap", Namespace="http://tempuri.org/"), DesignerCategory("code"), GeneratedCode("System.Web.Services", "2.0.50727.3053"), DebuggerStepThrough]
    public class MTOMWse : SoapHttpClientProtocol
    {
        private SendOrPostCallback AppendChunkOperationCompleted;
        private SendOrPostCallback CheckFileHashOperationCompleted;
        private SendOrPostCallback DownloadChunkOperationCompleted;
        private SendOrPostCallback GetFileSizeOperationCompleted;
        private SendOrPostCallback GetFilesListOperationCompleted;
        private SendOrPostCallback GetMaxRequestLengthOperationCompleted;
        private SendOrPostCallback HelloWorldOperationCompleted;
        private bool useDefaultCredentialsSetExplicitly;

        public event AppendChunkCompletedEventHandler AppendChunkCompleted;

        public event CheckFileHashCompletedEventHandler CheckFileHashCompleted;

        public event DownloadChunkCompletedEventHandler DownloadChunkCompleted;

        public event GetFileSizeCompletedEventHandler GetFileSizeCompleted;

        public event GetFilesListCompletedEventHandler GetFilesListCompleted;

        public event GetMaxRequestLengthCompletedEventHandler GetMaxRequestLengthCompleted;

        public event HelloWorldCompletedEventHandler HelloWorldCompleted;

        public MTOMWse()
        {
            this.Url = Settings.Default.MTOM_Library_MtomWebService_MTOM;
            if (this.IsLocalFileSystemWebService(this.Url))
            {
                this.UseDefaultCredentials = true;
                this.useDefaultCredentialsSetExplicitly = false;
            }
            else
            {
                this.useDefaultCredentialsSetExplicitly = true;
            }
        }

        [SoapDocumentMethod("http://tempuri.org/AppendChunk", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=SoapBindingUse.Literal, ParameterStyle=SoapParameterStyle.Wrapped)]
        public void AppendChunk(string FileName, [XmlElement(DataType="base64Binary")] byte[] buffer, long Offset)
        {
            base.Invoke("AppendChunk", new object[] { FileName, buffer, Offset });
        }

        public void AppendChunkAsync(string FileName, byte[] buffer, long Offset)
        {
            this.AppendChunkAsync(FileName, buffer, Offset, null);
        }

        public void AppendChunkAsync(string FileName, byte[] buffer, long Offset, object userState)
        {
            if (this.AppendChunkOperationCompleted == null)
            {
                this.AppendChunkOperationCompleted = new SendOrPostCallback(this.OnAppendChunkOperationCompleted);
            }
            base.InvokeAsync("AppendChunk", new object[] { FileName, buffer, Offset }, this.AppendChunkOperationCompleted, userState);
        }

        public void CancelAsync(object userState)
        {
            base.CancelAsync(userState);
        }

        [SoapDocumentMethod("http://tempuri.org/CheckFileHash", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=SoapBindingUse.Literal, ParameterStyle=SoapParameterStyle.Wrapped)]
        public string CheckFileHash(string FileName) => 
            ((string) base.Invoke("CheckFileHash", new object[] { FileName })[0]);

        public void CheckFileHashAsync(string FileName)
        {
            this.CheckFileHashAsync(FileName, null);
        }

        public void CheckFileHashAsync(string FileName, object userState)
        {
            if (this.CheckFileHashOperationCompleted == null)
            {
                this.CheckFileHashOperationCompleted = new SendOrPostCallback(this.OnCheckFileHashOperationCompleted);
            }
            base.InvokeAsync("CheckFileHash", new object[] { FileName }, this.CheckFileHashOperationCompleted, userState);
        }

        [return: XmlElement(DataType="base64Binary")]
        [SoapDocumentMethod("http://tempuri.org/DownloadChunk", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=SoapBindingUse.Literal, ParameterStyle=SoapParameterStyle.Wrapped)]
        public byte[] DownloadChunk(string FileName, long Offset, int BufferSize) => 
            ((byte[]) base.Invoke("DownloadChunk", new object[] { FileName, Offset, BufferSize })[0]);

        public void DownloadChunkAsync(string FileName, long Offset, int BufferSize)
        {
            this.DownloadChunkAsync(FileName, Offset, BufferSize, null);
        }

        public void DownloadChunkAsync(string FileName, long Offset, int BufferSize, object userState)
        {
            if (this.DownloadChunkOperationCompleted == null)
            {
                this.DownloadChunkOperationCompleted = new SendOrPostCallback(this.OnDownloadChunkOperationCompleted);
            }
            base.InvokeAsync("DownloadChunk", new object[] { FileName, Offset, BufferSize }, this.DownloadChunkOperationCompleted, userState);
        }

        [SoapDocumentMethod("http://tempuri.org/GetFileSize", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=SoapBindingUse.Literal, ParameterStyle=SoapParameterStyle.Wrapped)]
        public long GetFileSize(string FileName) => 
            ((long) base.Invoke("GetFileSize", new object[] { FileName })[0]);

        public void GetFileSizeAsync(string FileName)
        {
            this.GetFileSizeAsync(FileName, null);
        }

        public void GetFileSizeAsync(string FileName, object userState)
        {
            if (this.GetFileSizeOperationCompleted == null)
            {
                this.GetFileSizeOperationCompleted = new SendOrPostCallback(this.OnGetFileSizeOperationCompleted);
            }
            base.InvokeAsync("GetFileSize", new object[] { FileName }, this.GetFileSizeOperationCompleted, userState);
        }

        [SoapDocumentMethod("http://tempuri.org/GetFilesList", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=SoapBindingUse.Literal, ParameterStyle=SoapParameterStyle.Wrapped)]
        public string[] GetFilesList() => 
            ((string[]) base.Invoke("GetFilesList", new object[0])[0]);

        public void GetFilesListAsync()
        {
            this.GetFilesListAsync(null);
        }

        public void GetFilesListAsync(object userState)
        {
            if (this.GetFilesListOperationCompleted == null)
            {
                this.GetFilesListOperationCompleted = new SendOrPostCallback(this.OnGetFilesListOperationCompleted);
            }
            base.InvokeAsync("GetFilesList", new object[0], this.GetFilesListOperationCompleted, userState);
        }

        [SoapDocumentMethod("http://tempuri.org/GetMaxRequestLength", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=SoapBindingUse.Literal, ParameterStyle=SoapParameterStyle.Wrapped)]
        public long GetMaxRequestLength() => 
            ((long) base.Invoke("GetMaxRequestLength", new object[0])[0]);

        public void GetMaxRequestLengthAsync()
        {
            this.GetMaxRequestLengthAsync(null);
        }

        public void GetMaxRequestLengthAsync(object userState)
        {
            if (this.GetMaxRequestLengthOperationCompleted == null)
            {
                this.GetMaxRequestLengthOperationCompleted = new SendOrPostCallback(this.OnGetMaxRequestLengthOperationCompleted);
            }
            base.InvokeAsync("GetMaxRequestLength", new object[0], this.GetMaxRequestLengthOperationCompleted, userState);
        }

        [SoapDocumentMethod("http://tempuri.org/HelloWorld", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=SoapBindingUse.Literal, ParameterStyle=SoapParameterStyle.Wrapped)]
        public string HelloWorld() => 
            ((string) base.Invoke("HelloWorld", new object[0])[0]);

        public void HelloWorldAsync()
        {
            this.HelloWorldAsync(null);
        }

        public void HelloWorldAsync(object userState)
        {
            if (this.HelloWorldOperationCompleted == null)
            {
                this.HelloWorldOperationCompleted = new SendOrPostCallback(this.OnHelloWorldOperationCompleted);
            }
            base.InvokeAsync("HelloWorld", new object[0], this.HelloWorldOperationCompleted, userState);
        }

        private bool IsLocalFileSystemWebService(string url)
        {
            if ((url == null) || (url == string.Empty))
            {
                return false;
            }
            Uri uri = new Uri(url);
            return ((uri.Port >= 0x400) && (string.Compare(uri.Host, "localHost", StringComparison.OrdinalIgnoreCase) == 0));
        }

        private void OnAppendChunkOperationCompleted(object arg)
        {
            if (this.AppendChunkCompleted != null)
            {
                InvokeCompletedEventArgs args = (InvokeCompletedEventArgs) arg;
                this.AppendChunkCompleted(this, new AsyncCompletedEventArgs(args.Error, args.Cancelled, args.UserState));
            }
        }

        private void OnCheckFileHashOperationCompleted(object arg)
        {
            if (this.CheckFileHashCompleted != null)
            {
                InvokeCompletedEventArgs args = (InvokeCompletedEventArgs) arg;
                this.CheckFileHashCompleted(this, new CheckFileHashCompletedEventArgs(args.Results, args.Error, args.Cancelled, args.UserState));
            }
        }

        private void OnDownloadChunkOperationCompleted(object arg)
        {
            if (this.DownloadChunkCompleted != null)
            {
                InvokeCompletedEventArgs args = (InvokeCompletedEventArgs) arg;
                this.DownloadChunkCompleted(this, new DownloadChunkCompletedEventArgs(args.Results, args.Error, args.Cancelled, args.UserState));
            }
        }

        private void OnGetFileSizeOperationCompleted(object arg)
        {
            if (this.GetFileSizeCompleted != null)
            {
                InvokeCompletedEventArgs args = (InvokeCompletedEventArgs) arg;
                this.GetFileSizeCompleted(this, new GetFileSizeCompletedEventArgs(args.Results, args.Error, args.Cancelled, args.UserState));
            }
        }

        private void OnGetFilesListOperationCompleted(object arg)
        {
            if (this.GetFilesListCompleted != null)
            {
                InvokeCompletedEventArgs args = (InvokeCompletedEventArgs) arg;
                this.GetFilesListCompleted(this, new GetFilesListCompletedEventArgs(args.Results, args.Error, args.Cancelled, args.UserState));
            }
        }

        private void OnGetMaxRequestLengthOperationCompleted(object arg)
        {
            if (this.GetMaxRequestLengthCompleted != null)
            {
                InvokeCompletedEventArgs args = (InvokeCompletedEventArgs) arg;
                this.GetMaxRequestLengthCompleted(this, new GetMaxRequestLengthCompletedEventArgs(args.Results, args.Error, args.Cancelled, args.UserState));
            }
        }

        private void OnHelloWorldOperationCompleted(object arg)
        {
            if (this.HelloWorldCompleted != null)
            {
                InvokeCompletedEventArgs args = (InvokeCompletedEventArgs) arg;
                this.HelloWorldCompleted(this, new HelloWorldCompletedEventArgs(args.Results, args.Error, args.Cancelled, args.UserState));
            }
        }

        public string Url
        {
            get => 
                base.Url;
            set
            {
                if (!((!this.IsLocalFileSystemWebService(base.Url) || this.useDefaultCredentialsSetExplicitly) || this.IsLocalFileSystemWebService(value)))
                {
                    base.UseDefaultCredentials = false;
                }
                base.Url = value;
            }
        }

        public bool UseDefaultCredentials
        {
            get => 
                base.UseDefaultCredentials;
            set
            {
                base.UseDefaultCredentials = value;
                this.useDefaultCredentialsSetExplicitly = true;
            }
        }
    }
}

